package api.my_api;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class Test8 {
    public static void main(String[] args) throws ParseException {
        LocalDateTime now = LocalDateTime.now();
        // 日期格式化
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        System.out.println(now.format(dtf));

        // 日期解析
        String date = "2002年03月31日 14:32:43";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        Date parse = sdf.parse(date);
        System.out.println(parse);

        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        System.out.println(LocalDateTime.parse(date, dtf2));

        LocalDateTime of = LocalDateTime.of(2020, 2, 29, 23, 24, 24);
        System.out.println(of);
        LocalDateTime plusYears = of.plusYears(1L);
        System.out.println(plusYears);

        LocalDateTime minusYears = now.minusYears(10L);
        System.out.println(minusYears);

    }
}
